package com.shanghaionstar.discover.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.onstar.cn.common.util.CommonUtil;
import com.onstar.cn.framework.annotation.FindViewById;
import com.onstar.cn.framework.base.CommonAdapter;
import com.onstar.cn.framework.base.CommonViewHolder;
import com.onstar.cn.mag.dealer.PreferredDealerEntity;
import com.shanghaionstar.R;

import java.util.List;

/**
 * @ClassName: AroundDealerAdapter
 * @Description: 联系周边经销商
 * @author Xiaofeng Feng
 * @date 2015年8月18日 下午9:15:18
 */
public class AroundDealerAdapter extends CommonAdapter<PreferredDealerEntity> {

	private List<PreferredDealerEntity> aroundDealers;
	private Context context;
	private long selectItem = -1;
	private boolean isChange = false;

	public List<PreferredDealerEntity> getAroundDealers() {
		return aroundDealers;
	}

	public void setAroundDealers(List<PreferredDealerEntity> aroundDealers) {
		this.aroundDealers = aroundDealers;
	}

	/**
	 * @Description: TODO
	 * @author Xiaofeng Feng
	 * @date 2015年9月6日 下午2:55:48
	 */
	public AroundDealerAdapter(List<PreferredDealerEntity> datas, Context context) {
		super(datas, context);
		this.aroundDealers = datas;
		this.context = context;
	}

	@Override
	public void getView(int position, CommonViewHolder viewHolder) {
		ViewHolder holder = (ViewHolder) viewHolder;
		PreferredDealerEntity dealerEntity = aroundDealers.get(position);
		if(!CommonUtil.isNull(dealerEntity.getDealerName())) {
			holder.dealer_name.setText(dealerEntity.getDealerName().trim());
		}else {
			holder.dealer_name.setText("");
		}
		if(!CommonUtil.isNull(dealerEntity.getAddress())) {
			holder.dealer_addr.setText(dealerEntity.getAddress().trim());
		}else {
			holder.dealer_addr.setText("");
		}

		holder.dealer_distance.setText(dealerEntity.getDistanceWithUnit());
		holder.dealer_distance.setVisibility(View.VISIBLE);

		if (position == selectItem) {
			holder.dealer_distance.setVisibility(View.GONE);
			holder.iv_arrow.setImageResource(R.drawable.dealer_selected);
			holder.iv_arrow.setVisibility(View.VISIBLE);
		} else {
			holder.iv_arrow.setVisibility(View.INVISIBLE);
		}
	}

	@Override
	public CommonViewHolder getViewHolder() {
		return new ViewHolder();
	}

	/**
	 * 
	 * @ClassName: ViewHolder
	 * @Description: TODO
	 * @author Xiaofeng Feng
	 * @date 2015年9月6日 下午2:49:35
	 */
	private class ViewHolder extends CommonViewHolder {
		@FindViewById
		TextView dealer_name, dealer_addr, dealer_distance;
		@FindViewById
		ImageView iv_arrow;
	}

	@Override
	public int layoutId() {
		// TODO Auto-generated method stub
		return R.layout.discover_around_dealer_item;

	}

	public void setSelectItem(int arg2) {
		this.selectItem = arg2;

	}
}
